package sg.edu.nus.iss.billing.gui;

//Tan Pic Cheng

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import sg.edu.nus.iss.billing.entity.Customer;
import sg.edu.nus.iss.billing.entity.RecordState;
import sg.edu.nus.iss.billing.localization.MessageKeyManager;


public class ViewCustomerFieldPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String[] labelContent = {MessageKeyManager.getMessage("label.status"), MessageKeyManager.getMessage("label.accountNo"), MessageKeyManager.getMessage("label.NRIC/FIN"), MessageKeyManager.getMessage("label.saluation"), MessageKeyManager.getMessage("label.name"), MessageKeyManager.getMessage("label.emailAdd")};
		
	private JLabel lblCustHeader;
	private JLabel lblCustStatus;
	private JLabel lblCustID;
	private JLabel lblCustNRIC;
	private JLabel lblSaluation;
	private JLabel lblName;
	private JLabel lblEmail;
	
	private JLabel lblShowCustStatus;
	private JLabel lblShowCustID;
	private JLabel lblShowCustNRIC;
	private JLabel lblShowCustSaluation;
	private JLabel lblShowCustName;
	private JLabel lblShowCustEmail;
	
	private Customer customer;
	
	private int labelHeight = 20;
	private int labelWidth = 180;
	private int fieldControlX = 150;
	private int lblControlX = 10; 
	
	public ViewCustomerFieldPanel(Customer customer) {
		// TODO Auto-generated constructor stub
		super();
		init();
		this.customer = customer;
		/* No need validation as it is expected to be validated at the first place */
		lblShowCustID.setText(customer.getAccountNumber());
		lblShowCustNRIC.setText(customer.getNRIC());
		lblShowCustSaluation.setText(customer.getSalutation());
		lblShowCustName.setText(customer.getName());
		lblShowCustEmail.setText(customer.getEmail());		
		
		if(customer.getActive() == RecordState.ACTIVE)
			lblShowCustStatus.setText("ACTIVE");
		if(customer.getActive() == RecordState.DELETED)
			lblShowCustStatus.setText("DELETED");
		
	}
	private JLabel createLabel(String labelContents, int x, int y){
		
		JLabel labelName = new JLabel(labelContents);
		labelName.setVerticalTextPosition(SwingConstants.BOTTOM);
		labelName.setBounds(x, y, labelWidth, labelHeight);
		add(labelName);
		
		return labelName;		
		
	}
	private void init() {
		// TODO Auto-generated method stub
		setLayout(null);
		setPreferredSize(new Dimension(400, 300));
		setBounds(0, 0, 400, 300);
				
		lblCustHeader = createLabel("Customer Details:", 10, 5);
		
		int controly = 40;		
		
		for(int i = 0; i < labelContent.length; i++){
				
			switch(i){
			case 0: lblCustStatus = createLabel(labelContent[i], lblControlX, controly);
					//set new customer status as ACTIVE
					lblShowCustStatus = createLabel("", fieldControlX, controly);
					break;
			case 1: lblCustID =	createLabel(labelContent[i], lblControlX, controly);
					lblShowCustID = createLabel("", fieldControlX, controly);	
					break;
			case 2:	lblCustNRIC = createLabel(labelContent[i], lblControlX, controly);
					lblShowCustNRIC = createLabel("", fieldControlX, controly);
					break;
			case 3:	lblSaluation = createLabel(labelContent[i], lblControlX, controly);
					lblShowCustSaluation = createLabel("", fieldControlX, controly);
					break;
			case 4: lblName = createLabel(labelContent[i], lblControlX, controly);
					lblShowCustName = createLabel("", fieldControlX, controly);
					break;
			case 5:	lblEmail = createLabel(labelContent[i], lblControlX, controly);
					lblShowCustEmail = createLabel("", fieldControlX, controly);
					break;
			default:break;
			}//End of Switch
			controly= controly + 35;
		}//End of for
		
	}

}
